//
//  PersonalFileViewController.m
//  掌上宏力
//
//  Created by admin on 2017/4/26.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "PersonalFileViewController.h"
#import "PersonalViewModel.h"

static CGFloat Lab_H = 30;
static CGFloat Lab_W = 300;
static CGFloat Left_W = 80;
static CGFloat Interval = 5;
static CGFloat Interval_top = 10;
static CGFloat Interval_right = 20;

#define LAST_Y (_lastFrame.origin.y+_lastFrame.size.height)

@interface PersonalFileViewController ()
@property(nonatomic,strong) PersonalFileModel *personal;
@property (nonatomic,strong) PersonalViewModel *viewModel;
@property (nonatomic,assign) CGRect lastFrame;
@end

@implementation PersonalFileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的档案";
    [SVProgressHUD showWithStatus:@"请稍后..."];
    [self getPersonalDatas];
    
}
-(void)createView{
    User *user = [User currentUser];
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenW-Interval_right-80, 10, 80, 100)];
    extern NSString *icon_url;
    NSString *iconUrl = [NSString stringWithFormat:@"%@%@.jpg",icon_url,user.userId];
    [icon sd_setImageWithURL:[NSURL URLWithString:iconUrl]];
    [self.view addSubview:icon];
    
    NSArray *leftTitles1 = @[@"姓        名：",@"性        别：",@"婚姻状态："];
    NSArray *titles1 = @[_personal.userName,_personal.sex,_personal.marriage];
    _lastFrame = CGRectMake(0, 15, 0, 0);
    [self createViewsWithLeftTitles:leftTitles1 titles:titles1];
    
    //分割线
    UIView *line = [Factory createViewWithBackgroundColor:[UIColor lightGrayColor] frame:CGRectMake(Interval, LAST_Y+Interval_top, kScreenW-Interval*2, 1)];
    [self.view addSubview:line];
    _lastFrame = line.frame;
    
    NSArray *leftTitles2 = @[@"员工编号：",@"电        话：",@"宏  信  通：",@"所在部门：",@"职        位："];
    NSArray *titles2 = @[_personal.userId,_personal.phone,_personal.E_Card,_personal.department,_personal.job];
    [self createViewsWithLeftTitles:leftTitles2 titles:titles2];
    
    UIView *line2 = [Factory createViewWithBackgroundColor:[UIColor lightGrayColor] frame:CGRectMake(Interval, LAST_Y+Interval_top, kScreenW-Interval*2, 1)];
    [self.view addSubview:line2];
    _lastFrame = line2.frame;
    
    NSArray *leftTitles3 = @[@"学        历：",@"毕业院校：",@"身份证号：",@"籍        贯："];
    NSArray *titles3 = @[_personal.degree,_personal.university,_personal.cardId,_personal.nativePlace];
    [self createViewsWithLeftTitles:leftTitles3 titles:titles3];
    

}
-(void)createViewsWithLeftTitles:(NSArray *)leftTitles titles:(NSArray *)titles{
    for (int i=0; i<leftTitles.count; i++) {
        UILabel *leftL = [self createLeftLabWithFrame:CGRectMake(LeftDis, LAST_Y, Left_W, Lab_H) text:leftTitles[i] font:15];
        [self.view addSubview:leftL];
        UILabel *leftT = [Factory createLabelWithTitle:titles[i] frame:CGRectMake(leftL.right+Interval, LAST_Y, Lab_W, Lab_H) fontSize:15];
        [self.view addSubview:leftT];
        
        _lastFrame = leftT.frame;
    }

}
-(UILabel *)createLeftLabWithFrame:(CGRect)frame text:(NSString *)text font:(NSInteger)font{
    UILabel *leftL = [Factory createLabelWithTitle:text frame:frame fontSize:font];
    leftL.textAlignment = NSTextAlignmentRight;
    return leftL;
}

-(void)getPersonalDatas{
    
    _viewModel = [[PersonalViewModel alloc] init];
    [_viewModel getPersonalFileSuccess:^(PersonalFileModel *model) {
        _personal = model;
        [self createView];
        [SVProgressHUD dismiss];
    }];
}


@end
